package com.lwq.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Description:
 * Author: LiuWenQing
 * Datetime: 2021/6/10
 */
@Configuration
public class CorsConfig implements WebMvcConfigurer {

    /**
     * 服务端处理跨域
     * @param registry
     */
    @Order(value = 5)
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowCredentials(true)
                .allowedMethods("GET", "POST", "DELETE", "PUT","PATCH")
                .allowedHeaders("*")
                .maxAge(3600 * 24);
    }
}
